package com.android.view.activity.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.model.info.LocalSp;
import com.android.util.ToastUtil;
import com.android.R;
import com.android.app.CommonType;
import com.android.view.activity.base.Constants;
import com.android.view.activity.base.ToolbarBaseActivity;

import butterknife.BindView;

/**
 * 设置页面
 * Created by TenFace on 2018/4/19.
 */

public class SettingActivity extends ToolbarBaseActivity {
    private static final String TAG = SettingActivity.class.getSimpleName();
    private Context context;
    @BindView(R.id.exitAPP)
    Button exitAPP;
    @BindView(R.id.llLanguage)
    LinearLayout llLanguage;
    @BindView(R.id.llTheme)
    LinearLayout llTheme;
    @BindView(R.id.llColor)
    LinearLayout llColor;
    @BindView(R.id.llAbout)
    LinearLayout llAbout;
    @BindView(R.id.tvLanguage)
    TextView tvLanguage;
    @BindView(R.id.tvTheme)
    TextView tvTheme;
    @BindView(R.id.tvColor)
    TextView tvColor;
    @BindView(R.id.tvAbout)
    TextView tvAbout;

    @Override
    protected void setContentLayout() {
        setContentView(R.layout.activity_setting);
    }

    @Override
    protected void initView() {
        context = this;
        String userToken = LocalSp.getInstance(context).getSSOToken();
        if (!TextUtils.isEmpty(userToken)) {
            exitAPP.setVisibility(View.VISIBLE);
        } else {
            exitAPP.setVisibility(View.GONE);
        }
        initSomething();

    }

    private void initSomething() {
        String language = LocalSp.getInstance(context).getLanguageStatus();
        if (!TextUtils.isEmpty(language)) {
            switch (language) {
                case "zh":
                    tvLanguage.setText("简体中文");
                    break;
                case "en":
                    tvLanguage.setText("English");
                    break;
                default:
                    tvLanguage.setText("English");
            }
        } else {
            tvLanguage.setText("English");
        }
        int color = LocalSp.getInstance(context).getCheckColorStatus();
        switch (color) {
            case 0:
                tvColor.setText("Red+ Green-");
                break;
            case 1:
                tvColor.setText("Red- Green+");
                break;
            default:
                tvColor.setText("Red- Green+");
        }
    }

    @Override
    protected void obtainData() {

    }

    @Override
    protected void initEvent() {

        exitAPP.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LocalSp.getInstance(SettingActivity.this).clearDb();
                finish();
            }
        });
        llLanguage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(context, SettingLanguageActivity.class);
                startActivity(intent);
            }
        });
        llTheme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent intent = new Intent();
//                intent.setClass(context, SettingLanguageActivity.class);
//                startActivityForResult(intent, 100);
                ToastUtil.show("设置主题页面");
            }
        });
        llColor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(context, ColorPreferenceActivity.class);
                startActivity(intent);
            }
        });
        llAbout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent intent = new Intent();
//                intent.setClass(context, SettingLanguageActivity.class);
//                startActivityForResult(intent, 100);
                ToastUtil.show("关于页面");
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Constants.activityList.put(TAG, this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        initSomething();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                if (resultCode == 1) {
                    tvLanguage.setText(data.getStringExtra(CommonType.MYSELF_SETTING_LANGUAGE_STATUS));
                }
                break;
            case 2:
                if (resultCode == 2) {
                    tvColor.setText(data.getStringExtra(CommonType.MYSELF_SETTING_BOX_STATUS));
                }
                break;
        }
    }

}
